//
//  UserIdentifyCodeView.m
//  much
//
//  Created by weijunjie on 2019/1/3.
//  Copyright © 2019年 iOS. All rights reserved.
//

#import "UserIdentifyCodeView.h"
#import "CodeInputView.h"
@interface UserIdentifyCodeView()
@property (nonatomic, strong) UIView *popView;
@property (nonatomic, strong) UILabel *titleLabel;
@property (nonatomic, strong) UIButton *closeBtn;
@property (nonatomic, strong) UILabel *descLabel;
@property (nonatomic, strong) UILabel *countDownLabel;
@property (nonatomic, strong) CodeInputView *inputView;

@end
@implementation UserIdentifyCodeView

- (instancetype)init
{
    self = [super init];
    if (self) {
        self.backgroundColor = [UIColor colorWithWhite:0 alpha:0.5];
        self.layer.cornerRadius = 5;
        self.layer.masksToBounds = YES;
    }
    return self;
}

- (void)setIdentity:(NSString *)identity {
    _identity = [identity copy];
    self.inputView.phone = identity;
    self.countDownLabel.text = @"59秒后重新发送";
    self.descLabel.text = [NSString stringWithFormat:@"验证码已发送至%@",[identity changePhone]];
}

#pragma mark - 懒加载
- (UIView *)popView {
    if (!_popView) {
        _popView = [[UIView alloc] init];
        _popView.backgroundColor = [UIColor whiteColor];
        [self addSubview:_popView];
        [_popView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.width.mas_equalTo(315);
            make.height.mas_equalTo(245);
            make.top.equalTo(self).offset(138);
            make.centerX.equalTo(self);
        }];
    }
    return _popView;
}


- (UIButton *)closeBtn {
    if (!_closeBtn) {
        _closeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_closeBtn setImage:[UIImage imageNamed:@"pop_close"] forState:UIControlStateNormal];
        [self.popView addSubview:_closeBtn];
        [_closeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.popView).offset(20);
            make.right.equalTo(self.popView).offset(-20);
            make.width.height.mas_equalTo(11);
        }];
        [_closeBtn addTarget: self action:@selector(closeBtnAction) forControlEvents:UIControlEventTouchUpInside];
    }
    return _closeBtn;
}

- (UILabel *)titleLabel {
    if (!_titleLabel) {
        _titleLabel = [[UILabel alloc] init];
        _titleLabel.text = @"请输入验证码";
        _titleLabel.font = APPFONT(20);
        _titleLabel.textColor = Color34;
        [self.popView addSubview:_titleLabel];
        [_titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.closeBtn);
            make.centerX.equalTo(self.popView);
        }];
    }
    return _titleLabel;
}

- (UILabel *)descLabel {
    if (!_descLabel) {
        _descLabel = [[UILabel alloc] init];
        _descLabel.font = APPFONT(15);
        _descLabel.textColor = Color140;
        [self.popView addSubview:_descLabel];
        [_descLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.titleLabel.mas_bottom).offset(20);
            make.centerX.equalTo(self.popView);
        }];
    }
    return _descLabel;
}

- (UILabel *)countDownLabel {
    if (!_countDownLabel) {
        _countDownLabel = [[UILabel alloc] init];
        _countDownLabel.font = APPFONT(15);
        _countDownLabel.textColor = Color140;
        [self.popView addSubview:_countDownLabel];
        [_countDownLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.descLabel.mas_bottom).offset(20);
            make.centerX.equalTo(self.popView);
        }];
    }
    return _countDownLabel;
}

- (CodeInputView *)inputView {
    if (!_inputView) {
        _inputView = [[CodeInputView alloc] init];
        [self.popView addSubview:_inputView];
        [_inputView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.equalTo(self.popView);
            make.bottom.equalTo(self.popView).offset(-40);
            make.height.mas_equalTo(55);
        }];
        _inputView.inputViewBlock = self.inputViewBlock;
    }
    return _inputView;
}

- (void)closeBtnAction {
    [self removeFromSuperview];
}

@end
